package com.white.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.white.bean.Follow;
import com.white.bean.FollowView;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface FollowMapper extends BaseMapper<Follow> {

    String TABLE_NAME = " follow ";
    String SELECT = "select * from" + TABLE_NAME + "where ";
    int LIMIT = 10;
    String CREATE_TIME = "createTime";

    @Select(SELECT + "beFollowUserId = #{beFollowUserId} and followUserId = #{followUserId} order by " + CREATE_TIME + " desc limit " + LIMIT)
    List<Follow> mySearch(Follow follow);

    @Select("select u.userId, f.beFollowUserId authorId, u.headImage, u.name, f.createTime from\n" +
            "user u, follow f\n" +
            "where u.userId = f.beFollowUserId and f.followUserId = #{userId} order by " + CREATE_TIME + " desc limit " + LIMIT)
    List<FollowView> getFollowById(Long userId);

    @Select("select u.userId, f.beFollowUserId authorId, u.headImage, u.name, f.createTime from\n" +
            "user u, follow f\n" +
            "where u.userId = f.followUserId and f.beFollowUserId = #{userId} order by " + CREATE_TIME + " desc limit " + LIMIT)
    List<FollowView> getFanById(Long userId);

    @Delete("delete from" + TABLE_NAME + "where followUserId = #{followUserId} and beFollowUserId = #{beFollowUserId}")
    void myDelete(Follow follow);
}
